package com.VancouverTongue.database;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Random;

import java.util.Date;

//database import class

public class HelpObj {

	/**
	 * @param args
	 */

	protected HelpObj() {

	}

	/*
	 * check the length of the string if the length of the string is less than
	 * the limit length value, return string else, return substring
	 */
	public static String checkString(String s, int length) {
		if (s==null || s.length() <= length)
			return s;

		else {
			String str = s.substring(0, length - 1);
			return str;
		}

	}


	public static ArrayList<String> cut(String s) {
		ArrayList<String> message_list = new ArrayList<String>();

		int length = s.length();
		for (int i = 0; i < length; i += 50)
			message_list.add(s.substring(i, Math.min(length, i + 50)));

		return message_list;
	}


//	public static String getCurrentTime() {
//
//		String datesql = "";
//
//		java.util.Date currentDateTime = new java.util.Date();
//		Time currentTime = new Time(currentDateTime.getTime());
//		Date currentDate = new Date(currentDateTime.getTime());
//
//		datesql = currentDate.toString() + " " + currentTime.toString();
//
//		// System.out.println(datesql);
//		return datesql;
//	}

	public static String HTMLcheck(String s) {
		if(s==null){
			return null;
		}
		return s.replaceAll("&", "&amp;").replaceAll("<", "&lt;")
				.replaceAll(">", "&gt;").replaceAll("\"", "&quot;")
				.replaceAll("\'", "&apos;");
	}
	
	
	//get random generator in a specific range
	public static int getRandomNum(int input_number)
	{
		int tempNum = 0, randomnum =0, tens = 1 ;
		
		for (int i = 1; i <= input_number; i++)
		{
			tempNum = tempNum*10 + 9;
		}
		for (int j = 0; j< (input_number-1); j++)
		{
			tens = tens*10;
		}
		
		randomnum = new Random().nextInt(tempNum-tens)+tens;
		
		return randomnum;

	}
	
	
//	//convert string date time to long
//	public static long dateToLong(String date)
//	{
//
//		 date = date.replaceAll(" ", "");
//		 date = date.replaceAll("-", "");
//		 date = date.replaceAll(":", "");
//
//		 long date_long = Long.parseLong(date);
//
//		 return date_long;
//	}
	
	public static String expireTime(long days){
		if(days<0){
			return "null";
		}
		
		Date d = new Date();
		long time = new Date().getTime();
		time += days*24*3600*1000;
		System.out.println(days*24*3600*1000);
		d.setTime(time);
		Format format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return format.format(d);
		
	}

	
}
